<?php
  $yhendus=new mysqli("localhost", "if13", "ifikad", "if13_nils");
  if(isSet($_REQUEST["uusleht"])){
    $kask=$yhendus->prepare("INSERT INTO peoaeg (etteaste, syndmus, kellaaeg) VALUES (?, ?, ?)");
	echo $yhendus->error;
    $kask->bind_param("sss", $_REQUEST["etteaste"], $_REQUEST["sündmus"], $_REQUEST["kellaaeg"]);
    $kask->execute();
    header("Location: $_SERVER[PHP_SELF]");
    $yhendus->close();
    exit();
  }
  ?>
  <html>
  <head>
    <title>Peoaeg</title>
    <style type="text/css">
       #menyykiht{
         float: left;
         padding-right: 30px;
       }
       #sisukiht{
         float:left;
       }
       #jalusekiht{
         clear: left;
       }
    </style>
  </head>
  <body>
    <div id="menyykiht">
        <h2>PEOAJAD</h2>
        <ul>
		<?php
             $kask=$yhendus->prepare("SELECT id, etteaste FROM peoaeg");
             $kask->bind_result($id, $etteaste);
             $kask->execute();
             while($kask->fetch()){
               echo "<li><a href='?id=$id'>".
                          htmlspecialchars($etteaste)."</a></li>";
             }
          ?>
		  <?php
         if(isSet($_REQUEST["id"])){
            $kask=$yhendus->prepare("SELECT id, etteaste, sündmus, kellaaeg FROM peoaeg
               WHERE id=?");
            $kask->bind_param("i", $_REQUEST["id"]); 
            $kask->bind_result($id, $etteaste, $sündmus, $kellaaeg);
            $kask->execute();
            if($kask->fetch()){
              echo "<h2>".htmlspecialchars($etteaste)."</h2>";
              echo htmlspecialchars($sündmus);
			  echo htmlspecialchars($kellaaeg);
              echo "<br /><a href='?kustutusid=$id'>kustuta</a>";
            } else {
              echo "Vigased andmed.";
            }
         } 
      //   if(isSet($_REQUEST["lisamine"])){
           ?>